/*
 ============================================================================
 文件名 	: GameAudioPlayer.cpp
 描述	: CGameAudioPlayer类的实现.
 ============================================================================
 */

// 引用
#include "GameAudioPlayer.h"

// 音频文件路径
_LIT( KAudioFile, "c:\\data\\sounds\\up.wav");

// ============================ 成员函数 ===============================

// ---------------------------------------------------------
// CGameAudioPlayer::CGameAudioPlayer
// 构造函数.
// ---------------------------------------------------------
//
CGameAudioPlayer::CGameAudioPlayer(): iPlayer( NULL )
	{
	iState = (TInt)ENotReady;
	}

// ---------------------------------------------------------
// CGameAudioPlayer::ConstructL
// 两段构造函数.
// ---------------------------------------------------------
//
void CGameAudioPlayer::ConstructL()
	{
	iPlayer = CMdaAudioPlayerUtility::NewFilePlayerL( KAudioFile, *this );
	iPlayer->SetPriority( EMdaPriorityMax, EMdaPriorityPreferenceTime );
	}

// ---------------------------------------------------------
// CGameAudioPlayer::~CGameAudioPlayer
// 析构函数.
// ---------------------------------------------------------
//
CGameAudioPlayer::~CGameAudioPlayer()
	{
	if( iPlayer )
		{
		iPlayer->Stop();
		iPlayer->Close();
		}
	delete iPlayer;
	iPlayer = NULL;
	}

// ---------------------------------------------------------
// CGameAudioPlayer::NewL
// 构造函数.
// ---------------------------------------------------------
//
CGameAudioPlayer* CGameAudioPlayer::NewL()
	{
	CGameAudioPlayer* self = new (ELeave)CGameAudioPlayer;
	CleanupStack::PushL( self );
	self->ConstructL();
	CleanupStack::Pop();
	return self;
	}

// ---------------------------------------------------------
// CGameAudioPlayer::MapcInitComplete
// 播放器初始化完成.
// ---------------------------------------------------------
//
void CGameAudioPlayer::MapcInitComplete(TInt aError, 
		const TTimeIntervalMicroSeconds& /*aDuration*/)
	{
	User::LeaveIfError( aError );
	iState = (TInt)EReady;
	}

// ---------------------------------------------------------
// CGameAudioPlayer::MapcPlayComplete
// 播放完成.
// ---------------------------------------------------------
//
void CGameAudioPlayer::MapcPlayComplete( TInt aError )
	{
	User::LeaveIfError( aError );
	iPlayer->Stop();
	iState = (TInt)EReady;
	}

// ---------------------------------------------------------
// CGameAudioPlayer::CGameAudioPlayer
// 播放音频.
// ---------------------------------------------------------
//
void CGameAudioPlayer::Play()
	{
	if( iState == (TInt)EReady )
		{
		iState  = (TInt)EPlaying;
		iPlayer->Play();
		}
	}

// ---------------------------------------------------------
// CGameAudioPlayer::CGameAudioPlayer
// 游戏运行一步.
// ---------------------------------------------------------
//
void CGameAudioPlayer::GameChanged( CEngine* /*aGame*/ )
    {
    
    }

// ---------------------------------------------------------
// CGameAudioPlayer::CGameAudioPlayer
// 游戏暂停.
// ---------------------------------------------------------
//
void CGameAudioPlayer::GamePaused( CEngine* /*aGame*/ )
    {
    
    }

// ---------------------------------------------------------
// CGameAudioPlayer::CGameAudioPlayer
// 游戏结束.
// ---------------------------------------------------------
//
void CGameAudioPlayer::GameOver( CEngine* /*aGame*/ )
    {
    
    }

// ---------------------------------------------------------
// CGameAudioPlayer::CGameAudioPlayer
// 游戏小球撞线.
// ---------------------------------------------------------
//
void CGameAudioPlayer::BallHitsLine( CEngine* /*aGame*/ )
    {
    Play();
    }

// 文件结束
